package cn.xizikelif.basic.controller;

import cn.xizikelif.basic.util.ExcelUtil;
import cn.xizikelif.org.domain.Shop;
import cn.xizikelif.org.service.IShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/excel")
public class ExcalController {
    @Autowired
    private IShopService iShopService;
    /*导出*/
    @GetMapping("/exportExcel")
    public void exportExal(HttpServletResponse response){

        List<Shop> all = iShopService.findAll();
        ExcelUtil.exportExcel(all,"","",Shop.class,"店铺信息.xlsx",response);
    }
    /*导入*/
    @PostMapping("/importExcel")
    public void importExcel(@RequestParam("file") MultipartFile file){
        // 调用工具类导入
        List<Shop> shops = ExcelUtil.importExcel(file, 0, 2, Shop.class);
        // 调用批量新增的方法导入
        iShopService.addAll(shops);
    }

}
